package com.gxa.modules.sys.listener;

import com.gxa.modules.sys.service.CodeService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
@RabbitListener(queues = "queue-delay")
public class MessageListener {

    @Autowired
    private CodeService codeService;

    @RabbitHandler
    public  void receive01(String msg, Message message, Channel channel){

        Date date = new Date(System.currentTimeMillis());

        long time = date.getTime();

        java.sql.Date date1 = new java.sql.Date(time);

        this.codeService.updateState(date1);

        try {
            //消息确认
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
            String msg1 = null;
        }catch (Exception e){
            e.printStackTrace();
        }

        log.info("MessageListener 消费到了延迟消息---msg-->{}",msg);
    }

}
